<?php
   function countPg($count,$value)
   {
	$temp = $count / $value;
	if( $temp > intval($temp) )
		$temp = intval($temp) + 1;
	return $temp;
   }
   function page($str)
   {
	   //table(表名称),i(每页条数),pageNow(当前页),action(上下页动作)
	   $table = $str['table'];
	   $type = $str['type'];
	   $i = $str['i'];
	   $pageNow = $str['pageNow'];
	   $action = $str['action'];
	   $noNeed = $str['noNeed'];
	   //--------------------//
		if( empty($pageNow) )  $pageNow=1;
		if( M($table)->where("type='$type'")->count() > 4 ) 
		        $pages = countPg( ( M($table)->where("type='$type'")->count() - 4 ), $i ) + 1 ;
	    else    $pages = 1;
		if( !empty( $action ) )
		{
			switch( $action )
			{
				case "last": if( $pageNow > 1 )   $pageNow-=1; 
				             break;
				case "next": if($pageNow < $pages) $pageNow+=1; 
							 break;
				default:break;
			}
		}
		//-------------------//
		return array("pages" => $pages,
		             "pageNow" => $pageNow,
					 "pageData" => $pageData
		                       );
   }
//走势图生成
   function TrendChart($X,$Y,$title,$id)
{
	require "./Public/jpgraph/src/jpgraph.php";
	require "./Public/jpgraph/src/jpgraph_line.php";
	//---------------------------//
    // 创建图形
    $graph = new Graph(753,445);
    $graph->SetScale('textlin');
	$title = iconv('GB2312','UTF-8',$title);
    $graph->title->Set($title);
    $graph-> xaxis-> SetTickLabels($X);
    $graph-> xaxis-> SetFont(FF_SIMSUN,FS_BOLD); 

    // 创建折线图
    $lineplot=new LinePlot($Y);
    // 在图上创建测量点
    $graph->Add($lineplot);
    $lineplot->SetColor('red');
	//---------------------------//
	$graph->Stroke();
}